<?php 

Class videoController extends appController
{
	
	public function index()
	{
		$page=isset($_REQUEST['page'])?intval($_REQUEST['page']):1;
		$ad_list=Model('video')->ad_list($page);
		//$this->assign('search_action','index.php?g=admin&m=ad&a=search_group');
		$this->assign('art_list',$ad_list['data']);
		$this->assign('art_page',$ad_list['pagelink']);
		$this->display('index.html');
	}
	public function comment_list()
	{
		$page=isset($_REQUEST['page'])?intval($_REQUEST['page']):1;
		$ad_list=Model('video')->comment_list($page);
		//$this->assign('search_action','index.php?g=admin&m=ad&a=search_group');
		$this->assign('art_list',$ad_list['data']);
		$this->assign('art_page',$ad_list['pagelink']);
		$this->display('comment_list.html');
	}
	public function toggle()
	{
		$result=array('error'=>1,'content'=>Lang('INVALID_OPERATION'),'data'=>array());
		$info['status']=intval($_POST['value']);
		$id=intval($_POST['id']);
		if(isset($_POST['value']))
		{
			$res=Model('video')->update($info,array('table'=>'video_comment','id'=>$id));
			if($res)
			{
				$result['error']=0;
				$result['content']=Lang('SUCCESS_EDIT');
				if($info['status']==1)
				{
					$result['data']['text']='已通过';
					//$result['data']['status']=
				}
				else
				{
					$result['data']['text']='已无效';
				}
			}
		}
		print_r(json_encode($result));
		exit();
	
	}
	public function del_comment()
	{
		$result=array('error'=>0,'content'=>'删除成功','url'=>'');
		$id=isset($_REQUEST['id'])?$_REQUEST['id']:'';
		
			Model('video')->del(array('table'=>'video_comment','id'=>$id));
		
		print_r(json_encode($result));
	}
	public function add()
	{
		$this->assign('action','create');
		$this->display('video.html');
	
	}
	public function create()
	{
		//	$this->admin_priv('addmenu');
		$info['title']=isset($_POST['title'])?$_POST['title']:'';
		$info['thumb_url']=isset($_POST['thumb_url'])?$_POST['thumb_url']:'';
		$info['video_url']=isset($_POST['video_url'])?$_POST['video_url']:'';
		$info['add_time'] = $_SERVER['REQUEST_TIME'];
		$info['avatar']=isset($_POST['avatar'])?$_POST['avatar']:'';
	
		$data=array('error'=>0,'content'=>'新增成功','url'=>'');
	
		if($_POST['title']=='')
		{
			$data['error']=1;
			$data['content']='标题不能为空';
			$this->showMsg($data);
		}
		$pro = Model('video');
			$result = $pro->insert($info,'video');
	
			
			$this->showMsg($data);
	
	}
	public function edit()
	{
		
		//$this->admin_priv('addmenu');
		$id = intval($_GET['id']);
		$project = Model('video');
		$info = $project->get_video($id);
		$this->assign('art',$info);
		$this->assign('action','update');
		$this->display('video.html');
	}
	public function del()
	{
		$result=array('error'=>0,'content'=>'删除成功','url'=>'');
		$id=isset($_REQUEST['id'])?$_REQUEST['id']:'';
		
			Model('video')->del(array('table'=>'video','id'=>$id));
		
		print_r(json_encode($result));
	}
	public function update()
	{
		//	$this->admin_priv('addmenu');
		$info['title']=isset($_POST['title'])?$_POST['title']:'';
		$info['thumb_url']=isset($_POST['thumb_url'])?$_POST['thumb_url']:'';
		$info['video_url']=isset($_POST['video_url'])?$_POST['video_url']:'';
		$info['add_time'] = $_SERVER['REQUEST_TIME'];
		$info['avatar']=isset($_POST['avatar'])?$_POST['avatar']:'';
		$id = intval($_POST['id']);
		$data=array('error'=>0,'content'=>'编辑成功','url'=>'');
	
		if($_POST['title']=='')
		{
			$data['error']=1;
			$data['content']='标题不能为空';
			$this->showMsg($data);
		}
		$pro = Model('video');
		$result = $pro->update($info,array('table'=>'video','id'=>$id));
	
			
		$this->showMsg($data);
	
	}
}